'''
Created on 1 nov 2012

@author: Lanboost
'''

from CFilter import *
from CBufferedImage import *

class CFilterRainbow(CFilter):
    def applyFilter(self, aImage):
        bufferedimage = CBufferedImage(aImage)
        
        #init the values for the filter
        rp = 1
        gp = 0
        bp = 0
        
        imageslice = (bufferedimage.getWidth()/6.0)
        step = 1.0/imageslice
        
        for x in range(0, bufferedimage.getWidth()):
            for y in range(0, bufferedimage.getHeight()):
                pixel = bufferedimage.getPixel(x, y)
                r = int(pixel[0])
                g = int(pixel[1])
                b = int(pixel[2])
                newpixel = (int(r*rp),int(g*gp),int(b*bp))
                bufferedimage.setPixel(x, y, newpixel)
            if imageslice < x < imageslice*2:
                rp = rp-step
            if imageslice*4 < x:
                rp = rp+step
            if x<imageslice:
                gp=gp+step
            if imageslice*3 < x < imageslice*4:
                gp = gp-step
            if imageslice*2 < x < imageslice*3:
                bp = bp+step
        return bufferedimage.convertToImage()